/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.itschapala.dsw2.dao.EventosDaoLocal;
import mx.itschapala.dsw2.estado.Estado;
import mx.itschapala.dsw2.modelo.Eventos;

/**
 *
 * @author User
 */
@Stateless
public class EventosBL implements EventosBLLocal {
    @EJB
    private EventosDaoLocal eventosDao;
    
     
    @Override
    public Estado register(Eventos evn){
           if (eventosDao.findDuplicity(evn)) {
            return Estado.INCOMPLETE;
        } else {
            eventosDao.create(evn);
            return Estado.COMPLETE;
        }
    }

    @Override
    public Estado modify(Eventos evn) {
             if(evn.getEvent()==null || eventosDao.find(evn.getEvent())==null){
       return Estado.INCOMPLETE;
    } else{
            eventosDao.edit(evn);
            return Estado.COMPLETE;
        }
    }

    @Override
    public Estado delete(Eventos evn) {
          if (evn.getEvent() != null || eventosDao.find(evn.getEvent()) != null){
        eventosDao.remove(evn);
            return Estado.COMPLETE;
        }else {
            return Estado.INCOMPLETE;
        }
    }

    @Override
    public List<Eventos> getList() {
        return eventosDao.findAll();
    }
    
      public Eventos findById(Integer id) {
        return eventosDao.find(id);
    }
      
      public Eventos findName(String name)
      {
      return  eventosDao.find(name);
      }
    
    
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

}
